package com.lepu.app.fun.chat.core;


import com.lepu.app.fun.chat.util.Constants;

import org.jivesoftware.smack.packet.PacketExtension;

/**
 *
 */
public class ChatRoomPacketExtension implements PacketExtension {

    public static final String NAMESPACE = "jabber:kanebay:extbody:oob";
    public static final String NAMESPACE_EXTEND = "jabber:lepu:extinfo:oob";
    public static final String NAMESPACE_CLIENT = "jabber:client";
    public static final String NAMESPACE_AT_RECEIVE = "jabber:lepu:received";

    public static final String ELEMENT_NAME = "body-extension";
    public static final String ELEMENT_NAME_EXTEND = "extend-info";
    public static final String ELEMENT_NAME_MESSAGE = "message";
    private static final String ELEMENT_NAME_INFO_AT_RECEIVE = "received-info";

    public static final String SUB_ELEMENT_NAME_ATTACH = "attach";
    public static final String SUB_ELEMENT_NAME_TYPE = "type";
    public static final String SUB_ELEMENT_NAME_INFO_GROUP_ID = "info-group-id";
    public static final String SUB_ELEMENT_NAME_INFO_1 = "info-1";
    private static final String SUB_ELEMENT_NAME_INFO_AT_RECEIVE = "received";

    public static final String TAG_CHAT_TYPE = "chat-type";
    public static final String TAG_GROUP_ID = "group-id";

    private String elementName = "";    //body-extension
    private String subElementName = "";    //attach
    private String namespace = "";    //jabber:kanebay:extbody:oob

    private int messageType = 0;    //1=text,2=image,3=audio,4=vedio

    //=====================
    private String chatType = "";
    private String groupID = "";
    private String info1 = "";
    private String infoAtReceive = "";


    public ChatRoomPacketExtension(String elementName, String namespace) {
        this.elementName = elementName;
        this.namespace = namespace;
    }

    @Override
    public String getElementName() {
        return ELEMENT_NAME;
    }

    @Override
    public String getNamespace() {
        return NAMESPACE;
    }

    @Override
    public CharSequence toXML() {
        try {
            StringBuffer buf = new StringBuffer();

            buf.append("<").append(TAG_CHAT_TYPE).append(">");
            buf.append(getChatType());
            buf.append("</").append(TAG_CHAT_TYPE).append(">");

            buf.append("<").append(TAG_GROUP_ID).append(">");
            buf.append(getGroupID());
            buf.append("</").append(TAG_GROUP_ID).append(">");

            //info extend
            buf.append("<").append(elementName).append(" xmlns='").append(namespace).append("'>");
//            buf.append("<").append(SUB_ELEMENT_NAME_INFO_1).append(">");
//            buf.append(getInfo1());//value info
//            buf.append("</").append(SUB_ELEMENT_NAME_INFO_1).append(">");

            buf.append("<").append(SUB_ELEMENT_NAME_INFO_GROUP_ID).append(">");
            buf.append(getGroupID());//value info
            buf.append("</").append(SUB_ELEMENT_NAME_INFO_GROUP_ID).append(">");

            buf.append("</").append(elementName).append(">");

            //at
            buf.append("<").append(ELEMENT_NAME_INFO_AT_RECEIVE).append(" xmlns='").append(NAMESPACE_AT_RECEIVE).append("'>");

            buf.append("<").append(SUB_ELEMENT_NAME_INFO_AT_RECEIVE).append(">");
            buf.append(getInfoAtReceive());
            buf.append("</").append(SUB_ELEMENT_NAME_INFO_AT_RECEIVE).append(">");

            buf.append("</").append(ELEMENT_NAME_INFO_AT_RECEIVE).append(">");

            return new StringBuffer(buf.toString());
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }

    public int getMessageType() {
        return messageType;
    }

    public void setMessageType(int messageType) {
        this.messageType = messageType;
    }

    public String getChatType() {
        return chatType;
    }

    public void setChatType(String chatType) {
        this.chatType = chatType;
    }

    public String getGroupID() {
        return groupID;
    }

    public void setGroupID(String groupID) {
        this.groupID = groupID;
    }

    public String getInfo1() {
        return info1;
    }

    public void setInfo1(String info1) {
        this.info1 = info1;
    }

    public String getInfoAtReceive() {
        return infoAtReceive;
    }

    public void setInfoAtReceive(String infoAtReceive) {
        this.infoAtReceive = infoAtReceive;
    }
}
